package com.hq.fxh.Utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * @author 小谢
 * @ClassName SharedPreferenceUtils
 * @Description :
 * @Created 2016/11/15 0015
 */
public class SharedPreferenceUtils {
    private Context context;

    public SharedPreferenceUtils(Context context) {
        this.context = context;
    }

    /**
     * wifi是否打开
     *
     * @return
     */
    public static Boolean getSettingOpen(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("settingOpen", Activity.MODE_PRIVATE);
        String state = sharedPreferences.getString("isOpen", "");
        Boolean settingState = null;
        if (state.equals("yes")) {
            settingState = true;
        } else if (state.equals("no")) {
            settingState = false;
        } else if (state == null || state == "") {
            return false;
        }
        return settingState;
    }

    /**
     * memberId  uid
     */
    public static int getMemberId(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            int memberId = sharedPreferences.getInt("memberId", 0);
            return memberId;
        } else {
            return 0;
        }
    }

    public int getMemberId() {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            int memberId = sharedPreferences.getInt("memberId", 0);
            return memberId;
        } else {
            return 0;
        }
    }

    public void setMemberId(int memberId) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putInt("memberId", memberId).apply();
        } else {
            return;
        }
    }

    public static int getIs_active(Context context) {//是否激活 0未激活
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            int is_active = sharedPreferences.getInt("is_active", 0);
            return is_active;
        } else {
            return 0;
        }
    }
    public void setIs_active(int Is_active) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putInt("Is_active", Is_active).apply();
        } else {
            return;
        }
    }
    public int getLevel() {//企业或个人
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            int level = sharedPreferences.getInt("level", 0);
            return level;
        } else {
            return 0;
        }
    }

    public static String getMobile(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            String mobile = sharedPreferences.getString("account", "");
            return mobile;
        } else {
            return "";
        }
    }

    public void setMobile(String account) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putString("account", account).apply();
        }
    }

    public static String getExpire_dt(Context context) {//过期时间
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            String expire_dt = sharedPreferences.getString("expire_dt", "");
            return expire_dt;
        } else {
            return "";
        }
    }

    public String getPowderInfo() {
        SharedPreferences sharedPreferences = context.getSharedPreferences("PowderInfo", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            String mobile = sharedPreferences.getString("info", "");
            return mobile;
        } else {
            return "";
        }
    }

    public void setPowderInfo(String info) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("PowderInfo", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putString("info", info).apply();
        }
    }

    public static void setCityCode(Context context,int info) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("CityCode", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putInt("info", info).apply();
        }
    }

    public static int getCityCode(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("CityCode", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            int citycode = sharedPreferences.getInt("info", 0);
            return citycode;
        } else {
            return 0;
        }
    }

    public static boolean getIsShowAgreement(Context context) {//默认false,展示过一次设为true;false展示，true不展示
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            boolean IsShowAgreement = sharedPreferences.getBoolean("IsShowAgreement", false);//IsShowAgreement
            return IsShowAgreement;
        }
        return false;
    }

    public static void setIsShowAgreement(boolean IsShowAgreement, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putBoolean("IsShowAgreement", IsShowAgreement).apply();
        }
    }

    public static boolean getSharePrompt(Context context) {//默认false,展示过一次设为true;false未展示，true已展示
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            boolean IsShowAgreement = sharedPreferences.getBoolean("isPrompt", false);//IsShowAgreement
            return IsShowAgreement;
        }
        return false;
    }

    public static void setSharePrompt(boolean IsShowAgreement, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putBoolean("isPrompt", IsShowAgreement).apply();
        }
    }
    //是否悬浮
    public static void setIsflout(Context context,int isflout) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putInt("isflout", isflout).apply();
        } else {
            return;
        }
    }

    public static int getIsflout(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            int isflout = sharedPreferences.getInt("isflout", 1);
            return isflout;
        } else {
            return 1;
        }
    }

    //密码
    public static String getPwd(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            String pwd = sharedPreferences.getString("pwd", "");
            return pwd;
        } else {
            return "";
        }
    }
    public static void setPwd(Context context,String pwd) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putString("pwd", pwd).apply();
        }
    }
    public static int getIsCompany(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            int isCompany = sharedPreferences.getInt("isCompany", 0);
            return isCompany;
        } else {
            return 0;
        }
    }

    public void setIs_company(int company) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putInt("isCompany", company).apply();
        } else {
            return;
        }
    }

    /**
     * 资讯首页第一次，显示引导
     * @param context
     * @return
     */
    public static boolean getIsGuide(Context context) {//默认false,false未展示过；true已展示
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            boolean IsShowAgreement = sharedPreferences.getBoolean("IsGuide", false);//IsShowAgreement
            return IsShowAgreement;
        }
        return false;
    }

    public static void setIsGuide(boolean IsShowAgreement, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putBoolean("IsGuide", IsShowAgreement).apply();
        }
    }

    /**
     * 文章详情第一次，引导
     * @param context
     * @return
     */
    public static boolean getIsGuideArticle(Context context) {//默认false,false未展示过；true已展示
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            boolean IsShowAgreement = sharedPreferences.getBoolean("IsGuideArticle", false);//IsShowAgreement
            return IsShowAgreement;
        }
        return false;
    }

    public static void setIsGuideArticle(boolean IsShowAgreement, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putBoolean("IsGuideArticle", IsShowAgreement).apply();
        }
    }

    /**
     *美图第一次浏览，引导
     * @param context
     * @return
     */
    public static boolean getIsGuidePic(Context context) {//默认false,false未展示过；true已展示
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            boolean IsGuidePic = sharedPreferences.getBoolean("IsGuidePic", false);//IsShowAgreement
            return IsGuidePic;
        }
        return false;
    }

    public static void setIsGuidePic(boolean IsGuidePic, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putBoolean("IsGuidePic", IsGuidePic).apply();
        }
    }

    /**
     *
     * @param context
     * @return
     */

    public static boolean getIsGuideVideo(Context context) {//默认false,false未展示过；true已展示
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            boolean IsGuidePic = sharedPreferences.getBoolean("IsGuideVideo", false);//IsShowAgreement
            return IsGuidePic;
        }
        return false;
    }

    public static void setIsGuideVideo(boolean IsGuidePic, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putBoolean("IsGuideVideo", IsGuidePic).apply();
        }
    }
    //密码
    public static String getClientId(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            String clientId = sharedPreferences.getString("clientId", "");
            return clientId;
        } else {
            return "";
        }
    }
    public static void setClientId(Context context,String clientId) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putString("clientId", clientId).apply();
        }
    }

    //加粉第一次展示
    public static boolean getIsPowderFirst(Context context) {//
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            boolean IsShowAgreement = sharedPreferences.getBoolean("IsPowderFirst", false);//
            return IsShowAgreement;
        }
        return false;
    }

    public static void setIsPowderFirst(boolean IsShowAgreement, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putBoolean("IsPowderFirst", IsShowAgreement).apply();
        }
    }

    //记录第几次打开App
    public static int getOpenAppCount(Context context) {//
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            int openAppCount = sharedPreferences.getInt("OpenAppCount", 0);//
            return openAppCount;
        }
        return 0;
    }

    public static void setOpenAppCount(int openAppCount, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putInt("OpenAppCount", openAppCount).apply();
        }
    }

    //记录第几次好评
    public static int getGoodPriseCount(Context context) {//
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            int GoodPriseCount = sharedPreferences.getInt("GoodPriseCount", 1);//
            return GoodPriseCount;
        }
        return 1;
    }

    public static void setGoodPriseCount(int GoodPriseCount, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putInt("GoodPriseCount", GoodPriseCount).apply();
        }
    }

    public static String getCompanyName(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            String companyName = sharedPreferences.getString("CompanyName", "");
            return companyName;
        } else {
            return "";
        }
    }
    public static void setCompanyName(Context context,String companyName) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putString("CompanyName", companyName).apply();
        }
    }

    //是否评论过
    public static boolean getIsPrise(Context context) {//默认false,
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            boolean IsShowAgreement = sharedPreferences.getBoolean("IsPrise", false);//IsShowAgreement
            return IsShowAgreement;
        }
        return false;
    }

    public static void setIsPrise(boolean IsShowAgreement, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putBoolean("IsPrise", IsShowAgreement).apply();
        }
    }

    public static String getToken(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            String token = sharedPreferences.getString("token", "");
            return token;
        } else {
            return "";
        }
    }

    public static int getOldWatchCount(Context context) {//增加浏览量
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            int watchCount = sharedPreferences.getInt("watchCount", 0);
            return watchCount;
        } else {
            return 0;
        }
    }
    public static void setNewWatchCount(Context context,int watchCount) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putInt("watchCount", watchCount).apply();
        } else {
            return;
        }
    }

    //第一次上传图片或视频
    public static boolean getIsFirstUpLoadVideo(Context context) {//
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            boolean isFirstUpLoadVideo = sharedPreferences.getBoolean("isFirstUpLoadVideo", true);//
            return isFirstUpLoadVideo;
        }
        return false;
    }

    public static void setIsFirstUpLoadVideo(boolean isFirstUpLoadVideo, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putBoolean("isFirstUpLoadVideo", isFirstUpLoadVideo).apply();
        }
    }

    public static boolean getInstallGjPrompt(Context context) {//默认false,展示过一次设为true;false未展示，true已展示
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            boolean IsShowAgreement = sharedPreferences.getBoolean("isInstallGjPrompt", false);//IsShowAgreement
            return IsShowAgreement;
        }
        return false;
    }

    public static void setInstallGjPrompt(boolean IsShowAgreement, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putBoolean("isInstallGjPrompt", IsShowAgreement).apply();
        }
    }

    //未安装分享助手时，提示安装消息是否点击过 0未点击 1已点
    public static void setReadGJMessage(Context context,int isRead) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putInt("isRead", isRead).apply();
        } else {
            return;
        }
    }

    public static int getReadGJMessage(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("memberId", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            int isRead = sharedPreferences.getInt("isRead", 0);
            return isRead;
        } else {
            return 1;
        }
    }

    public static String getSpaceImageUrl(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("SpaceImagePersionCardUrl", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            String companyName = sharedPreferences.getString("SpaceImageUrl", "");
            return companyName;
        } else {
            return "";
        }
    }
    public static void setSpaceImageUrl(Context context,String companyName) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("SpaceImagePersionCardUrl", Activity.MODE_PRIVATE);
        if (sharedPreferences != null) {
            sharedPreferences.edit().putString("SpaceImageUrl", companyName).apply();
        }
    }
}
